package com.ss.android.article.base.feature.detail2.video;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.model.ArticleInfo.VideoExtendLink;
import com.ss.android.article.base.ui.LoadingFlashView;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.WebViewTweaker;
import com.ss.android.common.util.LoadUrlUtils;
import com.ss.android.newmedia.activity.FragmentActivity;
import com.ss.android.newmedia.webview.SSWebSettings;

public class VideoExtendLinkActivity extends FragmentActivity {
    LoadingFlashView a;
    Handler b;
    Runnable c;
    private WebView d;
    private VideoExtendLink e;

    public VideoExtendLinkActivity() {

        this.b = new Handler(Looper.getMainLooper());
        this.c = new Runnable() {

            public final void run() {
                if (VideoExtendLinkActivity.this.a.getVisibility() != View.VISIBLE) {
                    VideoExtendLinkActivity.this.a.setVisibility(View.VISIBLE);
                    VideoExtendLinkActivity.this.a.start();
                }
            }
        };
    }


    public int getLayout() {
        return R.layout.jm;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent v0 = this.getIntent();
        if (v0 == null) {
            this.finish();
        } else {
            v0.getStringExtra("arg_log_extra");
            this.e = v0.getParcelableExtra("arg_video_extend_link");
            if (this.e == null) {
                this.finish();
            } else {
                ArticleInfo.VideoExtendLink v3 = this.e;
                View v0_1 = this.findViewById(com.ss.android.article.browser.R.id.adv);
                View v1 = this.findViewById(com.ss.android.article.browser.R.id.adw);
                this.d = (WebView) this.findViewById(com.ss.android.article.browser.R.id.ady);
                this.a = (LoadingFlashView) this.findViewById(com.ss.android.article.browser.R.id.adz);
                ((TextView) v0_1).setText(v3.wapTitle);
                v1.setOnClickListener(new View.OnClickListener() {

                    public final void onClick(View arg2) {
                        VideoExtendLinkActivity.this.finish();
                    }
                });
                SSWebSettings.createWebSettings(this).setJavaScriptEnabled(this.d);
                this.d.setWebChromeClient(new WebChromeClient() {

                    public final void onProgressChanged(WebView arg4, int arg5) {
                        int v2 = 8;
                        super.onProgressChanged(arg4, arg5);
                        if (arg5 >= 95) {
                            VideoExtendLinkActivity.this.b.removeCallbacks(VideoExtendLinkActivity.this.c);
                            if (VideoExtendLinkActivity.this.a.getVisibility() != View.GONE) {
                                VideoExtendLinkActivity.this.a.stop();
                                VideoExtendLinkActivity.this.a.setVisibility(View.GONE);
                            }
                        }
                    }
                });
                this.d.setWebViewClient(new WebViewClient() {

                    public final void onPageFinished(WebView webView, String url) {
                        int v2 = View.GONE;
                        super.onPageFinished(webView, url);
                        VideoExtendLinkActivity.this.b.removeCallbacks(VideoExtendLinkActivity.this.c);
                        if (VideoExtendLinkActivity.this.a.getVisibility() != v2) {
                            VideoExtendLinkActivity.this.a.stop();
                            VideoExtendLinkActivity.this.a.setVisibility(v2);
                        }
                    }

                    public final void onPageStarted(WebView arg5, String arg6, Bitmap arg7) {
                        super.onPageStarted(arg5, arg6, arg7);
                        VideoExtendLinkActivity.this.b.postDelayed(VideoExtendLinkActivity.this.c, 350);
                    }

                    public final void onReceivedSslError(WebView arg1, SslErrorHandler arg2, SslError arg3) {
                        arg2.proceed();
                    }
                });
                LoadUrlUtils.loadUrl(this.d, v3.url);
            }
        }
    }

    public void onDestroy() {
        if (this.d != null) {
            try {
                this.d.stopLoading();
                LoadUrlUtils.loadUrl(this.d, "about:blank");
                WebViewTweaker.clearWebviewOnDestroy(this.d);
            } catch (Throwable v0) {
            }
        }

        super.onDestroy();
    }

    public void onPause() {
        super.onPause();
        if (this.d != null) {
            try {
                this.d.onPause();
            } catch (Throwable v0) {
            }
        }
    }

    public void onResume() {
        super.onResume();
        if (this.d != null) {
            try {
                this.d.onResume();
            } catch (Throwable v0) {
            }
        }
    }
}

